package com.pjb.springbootjjwt.store.entity;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

public class Compare {

    public static boolean eq(String v, String c) throws IOException {
        if (StringUtils.isAnyEmpty(v, c)) throw new IOException("字符串为空");
        return v.trim().equals(c.trim());
    }

    public static boolean gt(String v, String c) throws IOException {
        if (StringUtils.isAnyEmpty(v, c)) throw new IOException("字符串转数字失败");
        return Double.parseDouble(v) > Double.parseDouble(c);
    }

    public static boolean gte(String v, String c) throws IOException {
        if (StringUtils.isAnyEmpty(v, c)) throw new IOException("字符串转数字失败");
        return Double.parseDouble(v) >= Double.parseDouble(c);
    }

    public static boolean lt(String v, String c) throws IOException {
        if (StringUtils.isAnyEmpty(v, c)) throw new IOException("字符串转数字失败");
        return Double.parseDouble(v) < Double.parseDouble(c);
    }

    public static boolean lte(String v, String c) throws IOException {
        if (StringUtils.isAnyEmpty(v, c)) throw new IOException("字符串转数字失败");
        return Double.parseDouble(v) <= Double.parseDouble(c);
    }

    public static void main(String[] args) throws IOException {
        System.out.println(gt("5", "1"));
        System.out.println(gte("5", "5"));
        System.out.println(gte("5", "15 "));
        System.out.println(eq("v5", "15 "));
        System.out.println(eq("v5", "v5 "));
    }
}
